package main

import (
    "bytes"
    "encoding/gob"
    "fmt"
)

type Student struct {
    Name string
    Age  int
    Data map[string]string
}




func main() {

    s1 := Student{
        Name: "Jason Yin",
        Age:  18,
        Data: map[string]string{
            "aa": "11",
        },
    }

    buf := bytes.Buffer{}

    encoder := gob.NewEncoder(&buf)

    err := encoder.Encode(s1)
    if err != nil {
        fmt.Println("编码失败,错误原因: ", err)
        return
    }

    decoder := gob.NewDecoder(bytes.NewReader(buf.Bytes()))

    var s2 Student
    fmt.Println("解码之前s2 = ", s2)

    decoder.Decode(&s2)
    fmt.Println("解码之前s2 = ", s2)
}
